import threading

# from selenium.webdriver.common.by import By
# from selenium.webdriver.support import expected_conditions

from domain.consts import user_dir_pool

lock = threading.Lock()

# def getEleWait(self, xpath):
#     ele = None
#     try:
#         ele = self.waiter.until(expected_conditions.presence_of_element_located(
#             (By.XPATH, xpath)
#         ))
#     except Exception as e:
#         print(f"{self.work_dir[0]}:没有找到元素")
#     return ele
#
# def getEleNoWait(self, xpath):
#     try:
#         return self.browser.find_element(By.XPATH, xpath)
#     except:
#         print(f"{self.work_dir[0]}:没有找到元素：{xpath}")
#         return None
#
# def getElesNoWait(self, xpath):
#     try:
#         return self.browser.find_elements(By.XPATH, xpath)
#     except:
#         print(f'{self.work_dir[0]}:没有找到元素{xpath}')
#         return None

def get_task_dir():
    with lock:
        dir = next(filter(lambda x : not x[1], user_dir_pool), None)
        if dir:
            dir[1] = True
            return dir
        else:
            return None